package canFormArray;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public boolean canFormArray(int[] arr, int[][] pieces) {
        int[][]map = new int[101][];
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < pieces.length; i++) {
            map[pieces[i][0]] = pieces[i];
            set.add(pieces[i][0]);
        }
        int[] tmp = new int[arr.length];
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            if(set.contains(arr[i])){
                for (int num: map[arr[i]]) {
                    tmp[index++] = num;
                }
            }
        }
        for (int i = 0; i < tmp.length; i++) {
            if(tmp[i]!=arr[i]){
                return false;
            }
        }
        return true;
    }
}
